package com.sloth.bear.controller;

import com.sloth.bear.dto.request.NamespaceRequest;
import com.sloth.bear.dto.vo.NamespaceVo;
import com.sloth.bear.service.NamespaceService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 命名空间管理
 */
@RestController
@RequestMapping("/namespace")
@RequiredArgsConstructor
public class NamespaceController {

    private final NamespaceService namespaceService;

    /**
     * 创建命名空间
     */
    @PostMapping
    public void createSpace(@Valid @RequestBody NamespaceRequest request) {
        namespaceService.createSpace(request);
    }

    /**
     * 命名空间列表
     */
    @GetMapping("/list")
    public List<NamespaceVo> listNameSpace() {
        return namespaceService.listNameSpace();
    }

    /**
     * 根据ID获取命名空间详情
     */
    @GetMapping("/{id}")
    public NamespaceVo getSpaceById(@PathVariable Long id) {
        return namespaceService.getSpaceById(id);
    }

    /**
     * 更新命名空间
     */
    @PutMapping("/{id}")
    public NamespaceVo updateSpace(@PathVariable Long id, @Valid @RequestBody NamespaceRequest request) {
        return namespaceService.updateSpace(id, request);
    }

    /**
     * 删除命名空间
     */
    @DeleteMapping("/{id}")
    public void deleteSpace(@PathVariable Long id) {
        namespaceService.deleteSpace(id);
    }
}